{% extends "base/base.html" %}
{% load i18n %}

{% block title %}{% trans "Modificar perfil" %}{% endblock %}

{% block page-header %}{% trans "Modificar perfil" %}{% endblock %}

{% block content %}
{#    stateId = {{ address.state.pk }}#}
{#    <br>#}
{#    municipalId = {{ address.municipal.pk }}#}
    <form action="." method="post">
        {% csrf_token %}
        <fieldset>
            {{ form.as_p }}
        </fieldset>
{#        <fieldset>#}
{#            {{ formA.as_p }}#}
{#        </fieldset>#}
        <fieldset class="submit-row">
            <p><button type="submit">{% trans "Modificar perfil" %}</button></p>
        </fieldset>
    </form>
{% endblock %}

{% block java_script %}
{#    {% include "state_js.html" %}#}
    <script type="text/javascript">
        $(document).ready(function () {

{#            var x=document.getElementById("id_country");#}
{#            var state_selected = {{ address.state.pk }};#}
{#            var municipal_selected = {{ address.municipal.pk }};#}
{#            alert(y);#}

{#            $("#id_state option[value='132']").attr("selected",true);#}
{#            $('#id_state option[value="132"]').prop('selected', true);#}

{#            var div_municipal = document.getElementById("div_municipal");#}

{#            Dajaxice.companies.get_states(Dajax.process, {'option': x.value, 'selected': state_selected});#}
{#            Dajaxice.companies.get_municipals(Dajax.process, {'option':state_selected, 'selected': municipal_selected});#}
{#            Dajaxice.companies.get_states(Dajax.process, {'option': x.value});#}
            $(function() {
                $('#id_country').change(
                    function() {
                        Dajaxice.companies.get_states(Dajax.process, {'option':this.value});
                        Dajaxice.companies.get_municipals(Dajax.process, {'option':0});
                    }
                );
                $('#id_state').change(
                    function() {
                        Dajaxice.companies.get_municipals(Dajax.process, {'option':this.value});
                    }
                );
            });

            // TODO: Hacer invisible el div, que no se vea el espacio en blanco del select municipal
            if (document.getElementById("id_municipal").value == 0) {
                $('#div_municipal').removeClass("visible").addClass("invisible");
            } else {
                $('#div_municipal').removeClass("invisible").addClass("visible");

            };
        });
    </script>
{% endblock %}
